/**
 * 
 */
package com.sfeir.client;

import com.google.gwt.user.client.Timer;

/**
 * @author Fran�ois LAROCHE
 *
 */
public abstract class SimpleAnimationTimer extends Timer {

	protected int nbRepetitions;
	private int delay;
	

	/**
	 * @param nbRepetitions
	 * @param delay
	 */
	public SimpleAnimationTimer(int nbRepetitions, int delay) {
		this.nbRepetitions = nbRepetitions;
		this.delay = delay;
		this.run();
	}

	@Override
	public void run() {
		if(this.nbRepetitions == 0) {
			endTimer();
			this.cancel();
		}
		else {
			this.nbRepetitions --;
			this.schedule(this.delay);
			doUpdate();
		}
	}
	
	protected abstract void doUpdate();

	protected abstract void endTimer();
	
	
}
